<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.util.ArrayList"%>
<%@page import="BUS.TuyenTauBUS"%>
<div class="row">
<div class="col-md-6">   
     <h4>Tuyến</h4>
     <div class="row">
         <div class="col-md-4">
     <h5>Ga đi</h5>
<select class="form-control input-sm ga" id="gaDi">
      <%
         ResultSet rs = BUS.GaBUS.TimKiemTatCa();
        while(rs.next())
        {
            %> 
            <option value="<%=rs.getString("id") %>"><%= rs.getString("ten") %></option>
            <%
        }
    %>
</select>
         </div>
         <div class="col-md-4">
     <h5>Ga đến</h5>
<select class="form-control input-sm ga" id="gaDen">
    <%
         ResultSet rs2 = BUS.GaBUS.TimKiemTatCa();
        while(rs2.next())
        {
            %> 
            <option value="<%=rs2.getString("id") %>" ><%= rs2.getString("ten") %></option>
            <%
        }
    %>
</select>
         </div>
  <div class="col-md-4">
     <h5>Ngày khởi hành</h5>
 <select id="ngayKhoiHanh" class="form-control input-sm"></select>
         </div>
     </div>
     <div class="row">
         <div class="col-md-4">
     <h5>Chuyến</h5>
 <select  class="form-control input-sm" id="Chuyen"></select>
         </div>
     

    <div class="col-md-4">
      <h5>Loại toa   </h5>
     <select class="form-control input-sm" id="toa">
         <option value="1">Ghế ngồi</option>
         <option value="2">Giường nằm</option>
     </select>
         </div>
        <div class="col-md-4">
      <h5>Danh sách toa</h5>
     <select class="form-control input-sm" id="DSToa"></select>
         </div>
</div>
<div class="row" id="tangphong" style="display:none">
    <div class="col-md-4">
         <h5>phòng</h5>
        <select class="form-control input-sm" id="DSPhong"></select>
    </div>
     <div class="col-md-4">
         <h5>Tầng</h5>
         <select class="form-control input-sm" id="tang">
             <option value="1">Tầng 1</option>
             <option value="2">Tầng 2</option>
         </select>
    </div>
</div>
<div class="row">
    
    <h4>Đối tượng</h4>
    <div class="col-md-4">
    <select class="form-control input-sm" id="doiTuong">
        <option value="1">Người lớn</option>
        <option value="2">Người già</option>
        <option value="3">Học sinh sinh viên</option>
    </select>
    </div>
</div>
    
</div>

<div class="col-md-5" id="Postion"></div>
<div class="col-md-5" id="giave"></div>
</div>

    <script src="Js/jquery-2.1.1.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
  $(".ga").click(function(){
      var di = document.getElementById("gaDi").value;
      var den = document.getElementById("gaDen").value;
    $.get("TTGKhoiHanh",
    {
      gaDi :di,
      gaDen :den
    },
    function(data,status){
      document.getElementById("ngayKhoiHanh").innerHTML = data;
    });
  });
  
   $("#ngayKhoiHanh").click(function(){
      var di = document.getElementById("gaDi").value;
      var den = document.getElementById("gaDen").value;
      var nd = document.getElementById("ngayKhoiHanh").value;
    $.get("LstChuyen",
    {
       gaDi :di,
      gaDen :den,
      ngayDi :nd
    },
    function(data,status){
      document.getElementById("Chuyen").innerHTML = data;
    });
  });
  
  $('#DSPhong').click(function(){
        LoadGiuong();
  });
  
  $('#tang').click(function(){
      LoadGiuong();
  });
  
  function LoadGiuong()
  {
      var tangid = document.getElementById("tang").value;
      var phongid =document.getElementById("DSPhong").value;
       $.get('LstGG',
        {
           phong: phongid,
           tang :tangid
        },
        function(data, status){
             document.getElementById("Postion").innerHTML = data;
        });
  }
  
  $("#DSToa").click(function(){
      var t = document.getElementById("DSToa").value;
      var lt = document.getElementById('toa').value;
     if(lt == 1)
         $.get('LstGG',
        {
           LoaiToa: 1,
           so_hieu: t
        },
        function(data, status){
             document.getElementById("Postion").innerHTML = data;
        });
        else
        {
            $.get('DSPhong',
                {
                   LoaiToa: 2,
                   so_hieu: t
                },
                function(data, status){
                     document.getElementById("DSPhong").innerHTML = data;
                });
        }
  });
  
  
  $("#toa").click(function(){
      var sh = document.getElementById("toa").value;
      var Idtau = document.getElementById("Chuyen").value;
      if(sh==1)
          $('#tangphong').hide();
      else
          $('#tangphong').show();
    $.get("LstToa",
    {
      LoaiToa:sh,
      tau :Idtau
    },
    function(data,status){
      document.getElementById("DSToa").innerHTML = data;
    });
  });
});


function onc(a)
{
      var id = a.id;
     document.getElementById(id).disabled = true;
     document.getElementById(id).style.backgroundColor ="red";
     alert(id);
      var di = document.getElementById("gaDi").value;
      var den = document.getElementById("gaDen").value;
      var ch = document.getElementById("Chuyen").selectedOptions[0].text;
      var tauid = document.getElementById("Chuyen").value;
      var t = document.getElementById("toa").value;
      var dt = document.getElementById("doiTuong").value;
      var sht = document.getElementById("DSToa").value;
      var phongid =document.getElementById("DSPhong").value;
    $.post("DatVe",
    {
        ghe: id,
        gaDi: di,
        gaDen: den,
        chuyen: ch,
        toa: t,
        doiTuong: dt,
        sohieutoa: sht,
        phong:phongid,
        tau: tauid
        
    },function(data,status){
        document.getElementById('giave').innerHTML = data;
    });
   
}
</script>